#include<bits/stdc++.h>
using namespace std;
int d[100050],v[100050],a[100050],p[100050];
int main(){
    freopen("detect2.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    int t;
    cin>>t;
    while(t--){
        long long cnt=0;
        int n,m,l,V;
        int L=m,R=1;
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++)cin>>p[i];
        for(int i=1;i<=n;i++){
            if(a[i]>0){
                double y=(V-v[i])*(V+v[i])/(2*a[i]);
                int x=lower_bound(p+1,p+m+1,y+d[i])-p;
                if(x<=m){
                    cnt++;
                    R=max(R,x);

                }
            }
            if(a[i]==0){
                if(v[i]>V){
                    int x=lower_bound(p+1,p+n+1,d[i])-p;
                    if(x<=m){
                        cnt++;
                        R=max(R,x);
                    }
                }
            }
            if(a[i]<0){
                if(v[i]>=V){
                    double y=(V*V-v[i]*v[i])/(2*a[i]);
                    int x=lower_bound(p+1,p+m+1,y+d[i])-p;
                    int z=lower_bound(p+1,p+m+1,d[i])-p;
                    if(x>1&&x!=z){
                        cnt++;
                        L=min(L,x);
                        R=max(R,z);
                    }
                }

            }
        }
        int ans=abs(R-L)+1;
        cout<<cnt<<" "<<m-ans<<endl;
    }
    return 0;
}
